<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改配件管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-parts-edit" th:object="${zsyhPlatformParts}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="partsType" th:field="*{partsType}" type="hidden" id="treeId" required/>
            <input name="factoryId" th:field="*{factoryId}" type="hidden" id="factoryId" required/>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">配件主图：</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="partsImages" th:field="*{partsImages}" required>
                            <div class="file-loading">
                                <input class="form-control file-upload" id="partsImages" name="file" type="file">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">主图视频：</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="partsVideourl" th:field="*{partsVideourl}">
                            <div class="file-loading">
                                <input class="form-control file-upload" id="partsVideourl" name="file" type="file" accept="video/*">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品名称：</label>
                        <div class="col-sm-8">
                            <input name="partsName" th:field="*{partsName}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品分类：</label>
                        <div class="col-sm-8">
                            <input name="partsTypeName" th:field="*{partsTypeName}" onclick="selectTypeTree()" id="treeName" type="text" class="form-control" readonly required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">所属厂家：</label>
                        <div class="col-sm-8">
                            <input id="factoryName" th:field="*{factoryName}" name="factoryName" class="form-control" type="text" onclick="selectFactory()" readonly required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品类型：</label>
                        <div class="col-sm-8">
                            <select name="partsClassification" class="form-control m-b" th:with="type=${@dict.getType('parts_class')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{partsClassification}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品单位(会长端)：</label>
                        <div class="col-sm-8">
                            <input name="partsUnit" th:field="*{partsUnit}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品单位(店铺端)：</label>
                        <div class="col-sm-8">
                            <input name="partsStoreUnit" th:field="*{partsStoreUnit}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品品牌：</label>
                        <div class="col-sm-8">
                            <select name="partsDistinguish" class="form-control m-b" th:with="type=${@dict.getType('parts_brand')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{partsDistinguish}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否有补助金：</label>
                        <div class="col-sm-8">
                            <select name="partsHasGrant" class="form-control m-b" th:with="type=${@dict.getType('zsyh_yesno')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{partsHasGrant}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否热门推荐：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isHotPush_' + dict.dictCode}" name="isHotPush" th:value="${dict.dictValue}" th:field="*{isHotPush}" required>
                                <label th:for="${'isHotPush_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">会长是否上架：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowProvince_' + dict.dictCode}" name="isShowProvince" th:value="${dict.dictValue}" th:field="*{isShowProvince}" required>
                                <label th:for="${'isShowProvince_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">配件店是否上架：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowCity_' + dict.dictCode}" name="isShowCity" th:value="${dict.dictValue}" th:field="*{isShowCity}" required>
                                <label th:for="${'isShowCity_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">维修师傅是否上架：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowWorker_' + dict.dictCode}" name="isShowWorker" th:value="${dict.dictValue}" th:field="*{isShowWorker}" required>
                                <label th:for="${'isShowWorker_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <!--<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品描述（会长端）：</label>
                        <div class="col-sm-8">
                            <textarea name="partsDetails" class="form-control" required>[[*{partsDetails}]]</textarea>
                        </div>
                    </div>
                </div>-->
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否包邮：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isPost_' + dict.dictCode}" name="isPost" th:value="${dict.dictValue}" th:field="*{isPost}" required>
                                <label th:for="${'isPost_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品描述(店铺端)：</label>
                        <div class="col-sm-8">
                            <textarea name="partsStoreDetails" class="form-control" required>[[*{partsStoreDetails}]]</textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">注意事项：</label>
                        <div class="col-sm-8">
                            <input type="hidden" class="form-control" th:field="*{partsAttention}">
                            <div class="summernote" id="partsAttention"></div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">使用说明：</label>
                        <div class="col-sm-8">
                            <input type="hidden" class="form-control" th:field="*{partsInstructions}">
                            <div class="summernote" id="partsInstructions"></div>
                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">人口销售额比例：</label>
                        <div class="col-sm-8">
                            <input name="populationSalesRatio" th:field="*{populationSalesRatio}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">销售额定金比例：</label>
                        <div class="col-sm-8">
                            <input name="salesPaymentRatio" th:field="*{salesPaymentRatio}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>-->

            <div class="row">
                <!--<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">大区合作政策：</label>
                        <div class="col-sm-8">
                            <textarea name="cooperationPolicy" class="form-control">[[*{cooperationPolicy}]]</textarea>
                        </div>
                    </div>
                </div>-->
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">补助金赔付条件：</label>
                        <div class="col-sm-8">
                            <textarea name="partsDamageDetails" class="form-control">[[*{partsDamageDetails}]]</textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <div class="row" style="height: 20px;">
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/parts";
        var isShowProviceDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowCityDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowWorkerDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isPostDatas = [[${@dict.getType('zsyh_yesno')}]];
        $("#form-parts-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-parts-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            debugger;
            var val = $("input[name='" + this.id + "']").val()
            var initialPreviewConfig = [] ;
            var delImg = new Object() ;
            delImg = generFilDel(val);
            initialPreviewConfig.push(delImg) ;
            $(this).fileinput({
                'uploadUrl': ctx + 'common/uploadOSS',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                previewFileType: ['image', 'html', 'text', 'video', 'audio', 'flash', 'object','other'],
                initialPreviewConfig: initialPreviewConfig,
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        function generFilDel(fileName){
            debugger;
            var o=new Object();
            o.caption = fileName ;
            o.url = "/api/common/del";
            o.key = fileName;

            if(fileName==null||fileName.indexOf(".")==-1){
                //return {"type":null,"fileType":null};
                o.type="image";
                o.filetype="image/"+fileTyp;
                return o;
            }

            var fileArr = fileName.split(".");
            var fileTyp=fileArr[fileArr.length-1];

            if(["bmp", "gif", "jpg", "jpeg", "png"].join(",").indexOf(fileTyp) !=-1){
                o.type="image";
                o.filetype="image/"+fileTyp;
                return o;
            }
            if(["mp3"].join(",").indexOf(fileTyp) !=-1){
                o.type="audio";
                o.filetype="audio/"+fileTyp;
                return o;
            }
            if(["swf", "flv" , "mp4","wav", "wma", "wmv", "mid", "avi", "mpg",
                "rm", "rmvb"].join(",").indexOf(fileTyp) !=-1 ){
                o.type="video";
                o.filetype="video/"+fileTyp;
                return o;
            }
            return o;

        }


        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/uploadOSS",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>